package test;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import org.junit.Before;
import org.junit.Test;

public class GetDay {

	private SimpleDateFormat format ;
	
	@Before
	public void initSimpleDateFormat(){
		format = new SimpleDateFormat("yyyy-MM-dd");
	}
	
	@Test
	public void testGetFirstDay(){
        Calendar cale = Calendar.getInstance(); 
		// 获取前月的第一天    
        cale = Calendar.getInstance();
        cale.add(Calendar.MONTH, 0);    
        cale.set(Calendar.DAY_OF_MONTH, 1);    
        String firstday = format.format(cale.getTime());
        
        System.out.println(firstday);
	}
	
	@Test
	public void testGetEndDay(){
		Calendar cale = Calendar.getInstance(); 
		// 获取前月的第一天    
        cale = Calendar.getInstance();    
        cale.add(Calendar.MONTH, 1);    
        cale.set(Calendar.DAY_OF_MONTH, 0);   
        String firstday = format.format(cale.getTime());
        
        System.out.println(firstday);
	}
	
	@Test
	public void testCalendar(){
		
		 Calendar calendar = Calendar.getInstance();
		 
		 calendar.set(Calendar.DAY_OF_MONTH,
	        		calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
        System.out.println(format.format(calendar.getTime()));
        
		 calendar.set(Calendar.DAY_OF_MONTH,
	        		calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
		 System.out.println(format.format(calendar.getTime()));
	}
}
